The Transmission Control Protocol (TCP) is a core protocol of the Internet. Nodes on the Internet use TCP to provide connections with other nodes. Furthermore, TCP guarantees reliable and in-order delivery of packets from a sender node to a receiver node. To use TCP, a node creates a TCP connection and then begins receiving or sending packets using the connection. Because a node may communicate with hundreds of other nodes on a network, the node may have hundreds of TCP connections. Each of the TCP connections consumes resources on the node. For instance, maintenance and monitoring of a TCP connection may require processor cycles and memory resources. Under normal circumstances, a first node terminates (i.e., tears down) a TCP connection with a second node when the first node has finished communicating with the second node. In particular, the first node may send a FIN segment, to which the second node sends an ACK segment or a FIN/ACK segment.
However, in some circumstances a network connection between two nodes on a network may fail. For instance, an intermediate device may malfunction, one of the nodes may crash, or a link may be severed. As a result, a first node may not receive a FIN segment from a second node and therefore be unaware that the second node has finished communicating and has terminated the session. Therefore, the first node continues to maintain the TCP connection. Meanwhile, the TCP connection continues to consume resources.
In general, nodes use TCP sockets to manage TCP connections. Standard TCP sockets use a “KeepAlive” behavior to identify idle TCP connections that should be removed. If a “KeepAlive” option of a TCP socket for a TCP connection from a first node to a second node is turned on, the socket maintains a timer that indicates when the socket last sent or received a successful communication. If 7200 seconds (i.e., 2 hours) have passed since the last successful communication, the first node sends a TCP keep-alive segment on the TCP connection. If the socket does not receive a response to the keep-alive segment, the socket waits seventy-five seconds and then sends a second TCP keep-alive segment. If the socket does not receive a response to the second TCP keep-alive segment, the socket waits seventy-five seconds and then sends a TCP third keep-alive segment. If the socket does not receive a response to the third TCP keep-alive segment, the socket may send a fourth TCP keep-alive segment. If the socket does not receive a response to the fourth TCP keep-alive segment, the socket may terminate the TCP connection. However, if the socket receives a response to any of the keep-alive segments, the socket resets the two-hour time and maintains the TCP connection.